package com.xja.tt.service.impl;



/**
 * 创建时间：周三
 * 创建人：王鹏
 * 文件名：com.xja.tt.service.impl
 */
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xja.tt.bean.Search;
import com.xja.tt.bean.Student;
import com.xja.tt.mapper.StudentMapper;
import com.xja.tt.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李岩
 * @date 2021/12/22-20:26
 * @describe
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;



    @Override
    public void addstu(Student student) throws Exception {
        int addstu = studentMapper.addstu(student);


    }

    @Override
    public Student finStudentByNumber(Integer num) {


        return studentMapper.findStudentByNum(num);
    }

    @Override
    public void updateStudent(Student student) throws Exception {
        studentMapper.upDateStudentByNum(student);}
    @Override
    public PageInfo<Student> findAllStudents(Search search) throws Exception {
        Integer pageNumInt=1;
        Integer pageSizeInt=4;
        if (search.getPageNum()!=null && !"".equals(search.getPageNum())){
            pageNumInt=Integer.valueOf(search.getPageNum());
        }
        if (search.getPageSize()!=null && !"".equals(search.getPageSize())){
            pageSizeInt=Integer.valueOf(search.getPageSize());
        }
        PageHelper.startPage(pageNumInt,pageSizeInt);
        List<Student> list = studentMapper.findAllStudents();
        PageInfo<Student> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void deleteStudent(Integer number) throws Exception {
        studentMapper.deleteStudent(number);
    }
}
